package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@ApiOperation("购物车相关接口")
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     * @param dto
     * @return
     */
   @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO dto) {

       return  shoppingCartService.add(dto);

    }

    /**
     * 查看购物车
     * @return
     */

    @GetMapping("/list")
    public Result list(){
       return shoppingCartService.list();

    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result clean(){

        return shoppingCartService.clean();
    }

    /**
     * 购物车商品删减
     * @param dto
     * @return
     */
    @PostMapping("/sub")
    public Result subtract(@RequestBody ShoppingCartDTO dto){

        return shoppingCartService.subtract(dto);

    }

}
